<?php
class Pageley_Serializer_Converter_Timestamp implements Pageley_Serializer_Converter {

    public function convertIntoFormat($value) {
        return $value !== null ? $value->format() : null;
    }

    public function convertFromFormat($value, $format = null, $serializedName = null) {
        $result = null;
        try {
            $result = $value !== null && $value !== ""? 
                ($format !== null ? Pageley_Util_Timestamp::parse($value, $format) :
                    Pageley_Util_Timestamp::parse($value)) : null;
        } catch(Pageley_Util_ParseException $e) {
            throw new Pageley_Serializer_Exception("Deserializing value '" . $value . "' as Timestamp failed.", 0, $e);
        }
        return $result;
    }
}